package com.zhongke.cotrun.controller;

import com.alibaba.fastjson.JSON;
import com.google.common.collect.Lists;
import com.zhongke.cotrun.common.util.APIResponse;
import com.zhongke.cotrun.model.enums.EnumConfigType;
import com.zhongke.cotrun.model.pojo.CommonConfig;
import com.zhongke.cotrun.model.pojo.Item;
import com.zhongke.cotrun.service.CommonConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 作者 yhl
 * 日期 2020-01-05 04:45:15
 * 描述 CommonConfig 服务
 */
@RestController
@RequestMapping("/config")
@CrossOrigin
@Api(tags = "配置服务")
public class CommonConfigController extends AbstractController {

    private final Logger logger = LoggerFactory.getLogger(CommonConfigController.class);

    @Resource
    public CommonConfigService commonConfigService;

    // http://localhost:8088/config/listUserArea.json
    @ApiOperation(value = "查询应用领域配置", notes = "查询应用领域配置", httpMethod = "GET", produces = MediaType.APPLICATION_JSON_VALUE)
    @RequestMapping(value = "/listUserArea.json")

    public APIResponse<List<Item>> listUserArea() {
        CommonConfig config = commonConfigService.selectByPrimaryKey(EnumConfigType.USE_AREA.getCode());
        if (config == null) {
            return APIResponse.returnFail("不存在该配置");
        }

        return APIResponse.returnSuccess(config.getConfig());
    }

    @ApiOperation(value = "查询技术领域配置", notes = "查询技术领域配置", httpMethod = "GET", produces = MediaType.APPLICATION_JSON_VALUE)
    @RequestMapping(value = "/listSkillArea.json")
   @ResponseBody
    public APIResponse<List<Item>> listSkillArea() {
        CommonConfig config = commonConfigService.selectByPrimaryKey(EnumConfigType.SKILL_AREA.getCode());
        if (config == null) {
            return APIResponse.returnFail("不存在该配置");
        }

        return APIResponse.returnSuccess(config.getConfig());
    }

    @ApiOperation(value = "查询成果类型配置", notes = "查询成果类型配置", httpMethod = "GET", produces = MediaType.APPLICATION_JSON_VALUE)
    @RequestMapping(value = "/listFruitType.json")
   @ResponseBody
    public APIResponse<List<Item>> listFruitType() {
        CommonConfig config = commonConfigService.selectByPrimaryKey(EnumConfigType.FRUIT_TYPE.getCode());
        if (config == null) {
            return APIResponse.returnFail("不存在该配置");
        }

        return APIResponse.returnSuccess(config.getConfig());
    }

    @ApiOperation(value = "查询融资阶段配置", notes = "查询融资阶段配置", httpMethod = "GET", produces = MediaType.APPLICATION_JSON_VALUE)
    @RequestMapping(value = "/listFinancingType.json")
   @ResponseBody
    public APIResponse<List<Item>> listFinancingType() {
        CommonConfig config = commonConfigService.selectByPrimaryKey(EnumConfigType.FINANCING_TYPE.getCode());
        if (config == null) {
            return APIResponse.returnFail("不存在该配置");
        }

        return APIResponse.returnSuccess(config.getConfig());
    }


    @ApiOperation(value = "查询当前阶段配置", notes = "查询当前阶段配置", httpMethod = "GET", produces = MediaType.APPLICATION_JSON_VALUE)
    @RequestMapping(value = "/listProcessType.json")
   @ResponseBody
    public APIResponse<List<Item>> listProcessType() {
        CommonConfig config = commonConfigService.selectByPrimaryKey(EnumConfigType.PROCESS_TYPE.getCode());
        if (config == null) {
            return APIResponse.returnFail("不存在该配置");
        }

        return APIResponse.returnSuccess(config.getConfig());
    }

    public static void main(String[] args) {
        List<Item> items = new ArrayList<>();
        Item item1 = new Item();
        item1.setId(1000);
        item1.setDesc("电子信息");
        item1.setList(Lists.newArrayList(new Item(1001, "绿色化工"), new Item(1002, "计算机软件"), new Item(1003, "计算机硬件"), new Item(1004, "计算机网络"), new Item(1005, "微电子、光电子"), new Item(1006, "数字音视频"), new Item(1007, "通信技术"), new Item(1008, "电子专用设备及测试仪表"), new Item(1099, "其他")));
        items.add(item1);

        Item item2 = new Item();
        item2.setId(1100);
        item2.setDesc("航空航天");
        item2.setList(Lists.newArrayList(new Item(1101, "航空技术"), new Item(1102, "航天技术")));
        items.add(item2);

        Item item3 = new Item();
        item3.setId(1200);
        item3.setDesc("先进制造");
        item3.setList(Lists.newArrayList(new Item(1201, "自动化机械及设备"), new Item(1202, "高性能、智能化仪器仪表"), new Item(1299, "其他")));
        items.add(item3);

        Item item4 = new Item();
        item4.setId(1300);
        item4.setDesc("生物医药、医疗器械");
        item4.setList(Lists.newArrayList(new Item(1301, "生物技术"), new Item(1302, "医药技术"), new Item(1303, "轻工、食品"), new Item(1304, "新型医疗器械"), new Item(1399, "其他")));
        items.add(item4);

        Item item5 = new Item();
        item5.setId(1400);
        item5.setDesc("新材料及应用");
        item5.setList(Lists.newArrayList(new Item(1401, "电子信息及半导体材料"), new Item(1402, "生物及医用材料"), new Item(1403, "先进汽车材料"), new Item(1404, "金属材料"), new Item(1405, "非金属材料及先进建筑材料"), new Item(1406, "高分子材料及复合材料"), new Item(1407, "纳米材料"), new Item(1499, "其他")));
        items.add(item5);

        Item item6 = new Item();
        item6.setId(1500);
        item6.setDesc("新能源与高效节能");
        item6.setList(Lists.newArrayList(new Item(1501, "新型能源"), new Item(1502, "石油天然气勘探开发与利用"), new Item(1503, "煤炭能源的综合利用"), new Item(1504, "电能与电力"), new Item(1505, "高效节能"), new Item(1599, "其他")));
        items.add(item6);

        Item item7 = new Item();
        item7.setId(1600);
        item7.setDesc("环境保护与资源综合利用");
        item7.setList(Lists.newArrayList(new Item(1601, "大气污染防治"), new Item(1602, "水污染防治"), new Item(1603, "固体废弃物处理"), new Item(1604, "环境监测及环境生态保护"), new Item(1605, "噪声及辐射污染防治"), new Item(1606, "资源综合利用"), new Item(1607, "海洋工程"), new Item(1699, "其他")));
        items.add(item7);

        Item item8 = new Item();
        item8.setId(1700);
        item8.setDesc("核应用");
        item8.setList(Lists.newArrayList(new Item(1701, "核应用技术")));
        items.add(item8);

        Item item9 = new Item();
        item9.setId(1800);
        item9.setDesc("农业技术");
        item9.setList(Lists.newArrayList(new Item(1801, "优良动植物新品种"), new Item(1802, "家畜良种胚胎生物"), new Item(1803, "生物农药及生物防治"), new Item(1804, "新型饲料、肥料及添加剂"), new Item(1805, "农业机械设备"), new Item(1806, "农副产品贮藏、加工"), new Item(1899, "其他")));
        items.add(item9);

        Item item10 = new Item();
        item10.setId(1900);
        item10.setDesc("现代交通");
        item10.setList(Lists.newArrayList(new Item(1901, "城市交通"), new Item(1902, "公路、铁路、水运、海运和空运"), new Item(1999, "其他")));
        items.add(item10);

        Item item11 = new Item();
        item11.setId(2000);
        item11.setDesc("城市建设和社会发展");
        item11.setList(Lists.newArrayList(new Item(2001, "城市建设"), new Item(2002, "城市安全"), new Item(2003, "文教、体育"), new Item(2099, "其他")));
        items.add(item11);

        System.out.println(JSON.toJSONString(items));
    }
}
